
package com.cmc.dao.hibernate;

import java.util.List;

import com.cmc.dao.hibernate.BaseDaoHibernate;
import com.cmc.model.OrgLevelSetting;
import com.cmc.dao.OrgLevelSettingDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class OrgLevelSettingDaoHibernate extends BaseDaoHibernate implements OrgLevelSettingDao {

    /**
     * @see com.cmc.dao.OrgLevelSettingDao#getOrgLevelSettings(com.cmc.model.OrgLevelSetting)
     */
    public List getOrgLevelSettings(final OrgLevelSetting orgLevelSetting) {
        return getHibernateTemplate().find("from OrgLevelSetting");

        /* Remove the line above and uncomment this code block if you want 
           to use Hibernate's Query by Example API.
        if (orgLevelSetting == null) {
            return getHibernateTemplate().find("from OrgLevelSetting");
        } else {
            // filter on properties set in the orgLevelSetting
            HibernateCallback callback = new HibernateCallback() {
                public Object doInHibernate(Session session) throws HibernateException {
                    Example ex = Example.create(orgLevelSetting).ignoreCase().enableLike(MatchMode.ANYWHERE);
                    return session.createCriteria(OrgLevelSetting.class).add(ex).list();
                }
            };
            return (List) getHibernateTemplate().execute(callback);
        }*/
    }

    /**
     * @see com.cmc.dao.OrgLevelSettingDao#getOrgLevelSetting(Long id)
     */
    public OrgLevelSetting getOrgLevelSetting(final Long id) {
        OrgLevelSetting orgLevelSetting = (OrgLevelSetting) getHibernateTemplate().get(OrgLevelSetting.class, id);
        if (orgLevelSetting == null) {
            log.warn("uh oh, orgLevelSetting with id '" + id + "' not found...");
            throw new ObjectRetrievalFailureException(OrgLevelSetting.class, id);
        }

        return orgLevelSetting;
    }

    /**
     * @see com.cmc.dao.OrgLevelSettingDao#saveOrgLevelSetting(OrgLevelSetting orgLevelSetting)
     */    
    public void saveOrgLevelSetting(final OrgLevelSetting orgLevelSetting) {
        getHibernateTemplate().saveOrUpdate(orgLevelSetting);
    }

    /**
     * @see com.cmc.dao.OrgLevelSettingDao#removeOrgLevelSetting(Long id)
     */
    public void removeOrgLevelSetting(final Long id) {
        getHibernateTemplate().delete(getOrgLevelSetting(id));
    }
}
